/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_aqjc/main", [
            "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
            "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
            "../../plugins/artTemplate/artTemplate",
            "../../common/tools",
            "../../common/componts",
            "../../pages/jls_aqjc/form",
            "../../pages/jls_aqjc/AqjcShowHide.html.js",
        ],
        function(require) {
            var comonts=require("../../common/componts");
            var AqjcForm=require("../../pages/jls_aqjc/form");
            var tmp=require("../../pages/jls_aqjc/AqjcShowHide.html");
            var aqjcId="aqjcId";
            var selectid;
            var top="30px";
            var aqjc='aqjc';
            var initTable=function(){
                comonts.initTable(aqjcId,{
                    title: 'Aqjc',
                    url:"/jls_aqjc/aqjcList",
                    toolbar:'#tool',
                    firstLoad:true,
                    pageSize: 20,
                    columns:[
                        {field: 'oid',title: '',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="aqjcIdRadio" id="aqjcIdRadio"' + rowIndex + 'value="' + rowData.oid + '" />';}},
                        {
                            field : 'id',
                            width : 150,
                            title:'id',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.id == null ? "" : row.id)+'</span>'
                            }},
                        {
                            field : 'jsbh',
                            width : 150,
                            title:'监所编号',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jsbh == null ? "" : row.jsbh)+'</span>'
                            }},
                        {
                            field : 'sj',
                            width : 150,
                            title:'时间',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.sj == null ? "" : row.sj)+'</span>'
                            }},
                        {
                            field : 'fzr',
                            width : 150,
                            title:'负责人',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fzr == null ? "" : row.fzr)+'</span>'
                            }},
                        {
                            field : 'fw',
                            width : 150,
                            title:'检查范围',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fw == null ? "" : row.fw)+'</span>'
                            }},
                        {
                            field : 'nr',
                            width : 150,
                            title:'检查内容',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.nr == null ? "" : row.nr)+'</span>'
                            }},
                        {
                            field : 'rs',
                            width : 150,
                            title:'检查人数',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rs == null ? "" : row.rs)+'</span>'
                            }},
                        {
                            field : 'jcjg',
                            width : 150,
                            title:'检查结果',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jcjg == null ? "" : row.jcjg)+'</span>'
                            }},
                        {
                            field : 'cljg',
                            width : 150,
                            title:'处理结果',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.cljg == null ? "" : row.cljg)+'</span>'
                            }},
                        {
                            field : 'psbz',
                            width : 150,
                            title:'psbz',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.psbz == null ? "" : row.psbz)+'</span>'
                            }},
                        {
                            field : 'wjcjrs',
                            width : 150,
                            title:'武警参加人数',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.wjcjrs == null ? "" : row.wjcjrs)+'</span>'
                            }},
                        {
                            field : 'jskcjrs',
                            width : 150,
                            title:'监所科参加人数',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jskcjrs == null ? "" : row.jskcjrs)+'</span>'
                            }},
                        {
                            field : 'zsjcry',
                            width : 150,
                            title:'zsjcry',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.zsjcry == null ? "" : row.zsjcry)+'</span>'
                            }},
                        {
                            field : 'jcxs',
                            width : 150,
                            title:'检查类型',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jcxs == null ? "" : row.jcxs)+'</span>'
                            }},
                        {
                            field : 'bz',
                            width : 150,
                            title:'备注',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.bz == null ? "" : row.bz)+'</span>'
                            }},
                        {
                            field : 'spyj',
                            width : 150,
                            title:'审批意见',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.spyj == null ? "" : row.spyj)+'</span>'
                            }},
                        {
                            field : 'bllx',
                            width : 150,
                            title:'办理类型',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.bllx == null ? "" : row.bllx)+'</span>'
                            }},
                        {
                            field : 'creator',
                            width : 150,
                            title:'creator',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.creator == null ? "" : row.creator)+'</span>'
                            }},
                        {
                            field : 'createtime',
                            width : 150,
                            title:'createtime',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.createtime == null ? "" : row.createtime)+'</span>'
                            }},
                        {
                            field : 'updator',
                            width : 150,
                            title:'updator',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.updator == null ? "" : row.updator)+'</span>'
                            }},
                        {
                            field : 'updatetime',
                            width : 150,
                            title:'updatetime',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.updatetime == null ? "" : row.updatetime)+'</span>'
                            }},
                        {
                            field : 'state',
                            width : 150,
                            title:'数据状态',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.state == null ? "" : row.state)+'</span>'
                            }},
                        ],
                    detailFormatter:function(index,rowData){
                        return '<table style="height:40px;width:100%"><tr><td><strong></strong></td></tr></table>'
                    },
                    onClickRow:function(rowIndex, rowData){
                        if (selectid != rowData.id) {
                            $("input[name='aqjcIdRadio']")[rowIndex].checked = true;
                            $('#' + aqjcId).datagrid("selectRow", rowIndex);
                            selectid = rowData.id;
                        } else if (selectid == rowData.id) {
                            $('#' + aqjcId).datagrid("unselectRow", rowIndex);
                            $("input[name='aqjcIdRadio']")[rowIndex].checked = false;
                            selectid = "";
                        }
                    },
                });
                $('#aqjcId').datagrid('resize', {
                    height: ($(window).height()-35 )
                });
            }
            var findAqjc=function(){
                $('#'+aqjcId).datagrid('clearSelections');
                $('#'+aqjcId).datagrid('load',{
                });
            }
            var bindAction=function(){
                //查询
                $("#aqjc_search").on("click",function(){
                    findAqjc();
                });
                //新增
                $("#aqjc_add").on("click",function(){
                        AqjcForm.show(findAqjc,{});
                });
                //修改
                $("#aqjc_update").on("click",function(){
                    var Aqjc=$("#"+aqjcId).datagrid('getSelected');
                    if(Aqjc){
                        AqjcForm.show(findAqjc,Aqjc);
                    }else{
                        $.messager.alert("提示","请选择要修改的记录!","info");
                    }
                });
                //删除
                $("#aqjc_remove").on("click",function(){
                    //把你选中的 数据查询出来。
                    var selectRows = $('#aqjcId').datagrid("getSelections");
                    if(selectRows==null||selectRows==undefined){

                        return  $.messager.alert("提示消息", "请选中要删的数据!");
                    }else{
                        $.messager.confirm("操作提示", "您确定要删除该条记录吗？", function (data) {

                            if(data) {
                                submitLoad();
                                $.ajax({
                                    type : "POST",  //提交方式
                                    url : "/jls_aqjc/aqjcDelete",//路径
                                    data : {id:selectRows[0].id},//数据，这里使用的是Json格式进行传输
                                    success : function(result) {
                                        if (result.success) {
                                            $.messager.alert("确定","删除成功","info");
                                            findAqjc();
                                        }else{
                                            removeLoad();
                                            $.messager.alert("确定","删除失败","info");
                                        }
                                    },
                                    complete:function(){
                                        removeLoad();
                                    },
                                });
                            }else {
                                return false;
                            }

                        });

                    }
                });
                comonts.ShowHide(aqjc,tmp);
            }
            var initView=function(){
                initTable();
                bindAction();
            }
            initView();

        });